package com.feiyu.user.controller;


import com.feiyu.common.controller.BaseController;
import com.feiyu.user.dto.UpdateInfo;
import com.feiyu.user.entity.User;
import com.feiyu.user.entity.UserInfo;
import com.feiyu.user.service.UserService;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tang ming
 * @since 2021-11-30
 */
@RestController
@RequestMapping("/user")
@AllArgsConstructor
public class UserController extends BaseController<UserService,User> {

    private UserService userService;

    @GetMapping("/userInfo")
    public R<UserInfo> userInfo(String account){
        return R.data(userService.userInfo(account));
    }

    @GetMapping("/detail/{id}")
    public R<User> userDetail(@PathVariable long id){
        return R.data(userService.getById(id));
    }


    @PostMapping("/add")
    public R newAccount(@RequestBody User user){
        return R.status(userService.saveNewAccount(user));
    }

    @PostMapping("/signup")
    public R signUp(@RequestBody User user){
        return R.status(userService.signUp(user));
    }

    @PostMapping("/updatepassword")
    public R updatePassword(@RequestBody UpdateInfo user){
        return R.status(userService.updatePassword(user));
    }

    @PostMapping("/updateemail")
    public R updateEmail(@RequestBody UpdateInfo user ){
        return R.status(userService.updateEmail(user));
    }

    @GetMapping("/exist")
    public R existAccount(String account){
        return R.status(userService.existAccount(account)||userService.existEmail(account));
    }

}

